import {hrAjax as proFetch} from 'src/hrpub/common/utils/utils';
import updateCardButtonStatus from "./updateCardButtonStatus";

export default function getOnePsnInfo(callback) {
    const {orgVal, pk_psndoc_bad, includeCheckedPsn, page} = this.state;
    const {form, cardPagination} = this.props;
    if (!pk_psndoc_bad) {
        form.EmptyAllFormValue('blackcard');
        updateCardButtonStatus.call(this, page, orgVal, false);
        return;
    }
    let postData = {
        includeCheckedPsn,
        pk_org: orgVal && orgVal.refpk,
        pk_psndoc_bad
    };

    return proFetch({
        url: '/nccloud/hrhi/blacklist/BlackListQueryOneAction.do',
        body: postData,
    })
        .then((res) => {
            if (res.success) {
                form.setFormItemsVisible('blackcard', res.data.visiableItem);
                form.setAllFormValue({'blackcard': res.data.form.blackcard});
                if (res.data.form.blackcard.rows[0].values.cause.value === null) {
                    form.setFormItemsValue('blackcard', {'cause': {value: '', display: ''}});
                }

                cardPagination.setCardPaginationId({
                    id: pk_psndoc_bad,
                    status: 1
                });

                updateCardButtonStatus.call(this, page, orgVal, res.data.form.blackcard.rows[0].values);

                callback && callback();
            }
        });
}
